<?php
	require_once('init.php');

	//Check Form
	if(isset($_POST['name'])&&$_POST['name']!='')
	{
		//Query Column Name
		if(!$adminDB->executeSQL("select fdName from ".$util->contentdbName().".tbColumn where fdName='".trim($_POST['name'])."'",$connID))
		{			
			//Try Insert Column
			if(!$adminDB->executeSQL("insert into ".$util->contentdbName().".tbColumn (fdName,fdParentID,fdTypeID) values ('".trim($_POST['name'])."','0','1')",$connID))
			{
				echo"<script>alert('类别添加失败！');</script>";
			}
			else
			{
				//Insert AdminLog
				$adminDB->executeSQL("insert into ".$util->userdbName().".tbAdminLog (fdOperatorID,fdAction,fdTarget,fdTime) values('".$_SESSION['adminid']."','INSERT','".$util->contentdbName().".tbColumn(fdName,fdParentID,fdTypeID) values (".trim($_POST['name']).",0,1)',now())",$connID);
				echo"<script>alert('类别添加成功！');</script>";
			}
		}
		else
		{
			echo"<script>alert('已存在同名类别！请保证类别名不重复');</script>";
		}
	}

	$smarty->display('admin_addcolumn.html');
	$connDB->closeConnID();

?>